﻿#region Header
//=============================================================================
//                          GShield (Game Shield)
//=============================================================================
//
// Original Programmer: Shawn Jackson
// Company: WaveTech Digital Technologies, Inc. (http://www.wtdt.com)
// Copyright: (c) 2009 WaveTech Digital Technologies, Inc. All Rights Reserved.
// Assembly: Model
// Code File Name: ConnectionString.cs
// Code File Date: 1/23/2009
//
// Code File Info: Helper class to get the connection strings for the project
//                 and protect the SSDS and Azure connection strings.
//=============================================================================
/*
 * UPDATES
 * -------
 */
#endregion Header

#region License

/*
  GShield - Game Shield
  Copyright (C) 2006-2007 WaveTech Digital Technologies, Inc.
                                http://www.wtdt.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#endregion License

#region Includes
using System.Configuration;
using Microsoft.Win32;
#endregion Includes

namespace WaveTech.GShield.Common
{
	public static class ConnectionStrings
	{
		#region Private Constants
		private const string RegistryPath = @"Software\WaveTech\GShield";
		private const string SSDSRegistryKey = "SSDSConnectionString";
		#endregion Private Constants

		#region SSDS Connection String
		public static string GetSsdsConnectionString()
		{
			#if (DEBUG)
						return GetSsdsConnectionStringFromRegistry();
			#endif
						return GetSsdsConnectionStringFromConfig();
		}

		private static string GetSsdsConnectionStringFromRegistry()
		{
			RegistryKey regKey = Registry.CurrentUser.OpenSubKey(RegistryPath);
			return (regKey != null) ? regKey.GetValue(SSDSRegistryKey).ToString() : null; 
		}

		private static string GetSsdsConnectionStringFromConfig()
		{
			return ConfigurationManager.ConnectionStrings["SsdsContext"].ConnectionString;
		}
		#endregion SSDS Connection String
	}
}